package com.ocean.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ocean.admin.core.annotation.Log;
import com.ocean.admin.core.annotation.enums.BusinessType;
import com.ocean.admin.model.dto.config.SysConfigDTO;
import com.ocean.admin.model.dto.config.SysConfigSaveDTO;
import com.ocean.admin.model.dto.config.SysConfigUpdateDTO;
import com.ocean.admin.model.vo.config.SysConfigVo;
import com.ocean.admin.service.ISysConfigService;
import com.ocean.core.util.response.ResultSet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 参数配置表 前端控制器
 * </p>
 *
 * @author zhang
 * @since 2022-08-16
 */
@Tag(name = "系统参数配置管理")
@RestController
@RequestMapping("/admin/sys-config")
public class SysConfigController {

    @Autowired
    private ISysConfigService iSysConfigService;

    /**
     * 新增参数配置
     *
     * @param saveDTO 参数信息
     * @return 新增结果
     */
    @Operation(summary = "新增系统参数配置")
    @PreAuthorize("@ss.hasPermission('system:config:saveConfig')")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping(value = "saveConfig")
    public ResultSet<String> saveConfig(@Validated @RequestBody SysConfigSaveDTO saveDTO) {
        return ResultSet.ok(iSysConfigService.saveConfig(saveDTO));
    }

    /**
     * 删除参数配置
     *
     * @param configIds 参数Id
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermission('system:config:removeConfig')")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @GetMapping("removeConfig/{configIds}")
    public ResultSet<String> removeConfig(@PathVariable Long[] configIds) {
        return ResultSet.ok(iSysConfigService.removeConfig(configIds));
    }

    /**
     * 修改参数配置
     *
     * @param updateDTO 参数信息
     * @return 修改结果
     */
    @Operation(summary = "修改参数配置")
    @PreAuthorize("@ss.hasPermission('system:config:updateConfig')")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updateConfig")
    public ResultSet<String> updateConfig(@Validated @RequestBody SysConfigUpdateDTO updateDTO) {
        return ResultSet.ok(iSysConfigService.updateConfig(updateDTO));
    }

    /**
     * 分页查询参数配置列表
     *
     * @param configDTO 查询条件
     * @return 分页结果
     */
    @PreAuthorize("@ss.hasPermission('system:config:pageList')")
    @Operation(summary = "分页查询参数配置列表")
    @PostMapping("/pageList")
    public ResultSet<IPage<SysConfigVo>> pageList(@Validated @RequestBody SysConfigDTO configDTO) {
        return ResultSet.ok(iSysConfigService.pageList(configDTO));
    }
}
